Thanks @jlagrone. Your second approach is what I was thinking of doing. Was hoping there was some sample code or hints from someone who was familiar with it. But I guess we'll just experiment and figure it out.
Post
Replies
Boosts
Views
Activity
I was able to work around this by making a wrapper struct for the binding that conforms to Hashable if the value is Hashable.
Then I am able to do the following in the NavigationLink:
NavigationLink(value: HashableBindingWrapper<Event>(binding: $event) { … }
// Later in file:
.navigationDestination(for: HashableBindingWrapper<Event>.self) { wrapper in
EventEditor(event: wrapper.binding)
}
It's ugly to need to do this instead of it being supported directly, but it seems to work. Thanks to Ben Scheirman for the suggestion.
Here's the code for HashableBindingWrapper:
struct HashableBindingWrapper<Value> {
let binding: Binding<Value>
}
extension HashableBindingWrapper: Equatable where Value: Equatable {
static func == (lhs: HashableBindingWrapper<Value>, rhs: HashableBindingWrapper<Value>) -> Bool {
lhs.binding.wrappedValue == rhs.binding.wrappedValue
}
}
extension HashableBindingWrapper: Hashable where Value: Hashable {
func hash(into hasher: inout Hasher) {
hasher.combine(binding.wrappedValue.hashValue)
}
}
In this case, I wanted to quickly send a screen shot of my work-in-progress to someone. As I mentioned, I could take a regular screen shot (and did), but having to crop the image is definitely a point of friction.
I could also imagine using screen shots to try out different layouts, taking a screenshot of each to show to others to compare.
I would imagine pretty much everything people use Simulator screenshots for would also be a use case for Xcode Preview screenshots, with the added advantage that Xcode Preview screenshots could be easily created subsets of the UI, not just the entire app.